package cn.usain.service.impl;

import cn.usain.dao.UserMapper;
import cn.usain.pojo.User;
import cn.usain.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import javax.annotation.Resource;



@Service
@Transactional
public class UserServiceImpl implements UserService {
   @Resource
    private UserMapper userMapper;

    public Page<User> findPage(String name,Integer pageNum) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        queryWrapper.like("name",name);
        Page<User> page = new Page<User>(pageNum,2);
        if(name!= null){
            Page<User> pageInfo = userMapper.selectPage(page, queryWrapper);
            return pageInfo;
        }else {
            Page<User> pageInfo = userMapper.selectPage(page, null);
            return pageInfo;
        }
    }



    @Override
    public User findById(int id) {
        return userMapper.selectById(id);
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public void del(int id) {
        userMapper.deleteById(id);
    }

    @Override
    public void add(User user) {
        userMapper.insert(user);
    }




}
